package com.hl.payServer.task;


import com.hl.payServer.model.PayTradeInfo;
import com.hl.payServer.model.enums.TradeState;
import com.hl.payServer.service.PayTradeInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * Created by Administrator on 2016-01-13.
 * 将成功支付的订单进行推送到各子系统
 */
@Component("issuedNotifiesTasks")
public class IssuedNotifiesTask extends Base {
	private static final Logger logger =  LoggerFactory.getLogger(IssuedNotifiesTask.class);

    /**
	 * 第三方支付回调定时器
     * 15秒执行一次,查数据库将支付成功的,通知次数在9次以内未通知成功的进行通知,
     */
    @Scheduled(fixedRate = 1000*5)
    void handlePaySuccess() {
    	List<String> list = new ArrayList();
    	list.add(TradeState.SUCCESS.type());
    	list.add(TradeState.PAYERROR.type());
    	list.add(TradeState.CLOSED.type());
    	list.add(TradeState.FINISHED.type());
		HashMap<String,Object> params= new HashMap<>();
		//状态为支付成功的'SUCCESS'  必须要放在list里，因为共用
        params.put("statusList", list);
		//通知状态为,未通知成功的
        params.put("notifieFlag", "0");
        params.put("haveNotifieUrl", "Y");
        params.put("notifieCount", "9");
//

        List<PayTradeInfo> payTradeInfos= payTradeInfoService.queryListSelfUse(params);
        if(payTradeInfos!=null) {
            for (PayTradeInfo payTradeInfo : payTradeInfos) {
            	goNotifies(payTradeInfo,payTradeInfoService);
            }
        }
    }

}
